package demo1;

import java.util.List;
import java.util.Stack;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {



    public ListNode removeNthFromEnd(ListNode head, int n) {
        if(head.next == null){
            return null;
        }
        ListNode pcur = head;
        ListNode prev = head;
        while (n > 0) {
            pcur = pcur.next;
            n--;
        }
        ListNode prevN = prev;
        while (pcur != null) {
            pcur = pcur.next;
            prevN = prev;
            prev = prev.next;
        }
        if(prev == head){
            return head.next;
        }
        prevN.next = prev.next;
        return head;
    }

    public boolean isPalindrome1(int x) {
        String str = Integer.toString(x);
        int l = 0;
        int r = str.length()-1;
        while(l<r){
            if(str.charAt(l) != str.charAt(r)){
                return false;
            }
        }
        return true;
    }

    public static boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        int x2 = x;
        Stack<Integer> stack = new Stack<>();
        while (x2 > 0) {
            stack.push(x2%10);
            x2 /= 10;
        }
        while (x > 0) {
            if (stack.pop() != x % 10) {
                return false;
            }
            x /= 10;
        }
        return true;
    }

    public int twoEggDrop(int n) {
        int count = 0;
        while (n >= 0) {
            n -= count;
            count++;
        }
        return count-1;
    }
}
